<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link href="skin/base.css" type="text/css" rel="stylesheet" />
<link href="skin/user.css" type="text/css" rel="stylesheet">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
</head>
<body ontouchstart>
<div id="main" class="loading">
  <div class="user"> </div>
</div>
</body>
<script>
	zy_init();
    window.uexOnload = function(type){
        if (!type){
			uexWindow.setBounce("1");
			uexXmlHttpMgr.onData = function(opId, status, data){	
				if (status == 1) {
					data = JSON.parse(data);
					if (opId == 1) {
						$$('main').className = '';
						if (data['success'] == 'OK') {
							var html = '<div class="user"><ul class="list">';
							var list = data['data'];
							for (i in list) {
								html += '<li>' +
								'<div class="l" ontouchstart="zy_touch(\'down\')"  onclick="javascript:jump(' +
								list[i]['coupons']['id'] +');">' +
								'<h3>' +list[i]['coupons']['title'] +'</h3>' +
								'<span>有效期：' +list[i]['coupons']['start_time'] +	'到' +list[i]['coupons']['end_time'] +'</span>' +
								'<span>消费密码：' +list[i]['pwd'] +'</span>' +
								'</div>';
								
								html += '<div class="r">';
								if (list[i]['isConsume'] == 1) {
									html += '<span class="b" id="coupons_'+list[i]['id']+'">已使用</spnn>';
								}else if (list[i]['isConsume'] == 0) {
									if (list[i]['coupons']['is_time'] > 0) {
										html += '<span class="c" id="coupons_'+list[i]['id']+'">已过期</spnn>';
									}else {
										html += '<span class="a" id="coupons_'+list[i]['id']+'" onclick="javascript:post(' + list[i]['id'] + ');">使用</spnn>';
									}
								}
								html += '</div></li>';
							}
							html += '</ul></div>';
							$$('main').innerHTML = html;
						}else {
							uexWindow.toast("0", "5", data['msg'], 1000);
						}
					}else if(opId==2){
						if (data['success'] == 'OK') {
							$$('coupons_'+data['data']['id']).className = 'b';
							$$('coupons_'+data['data']['id']).innerHTML = '已使用';
							$$('coupons_'+data['data']['id']).setAttribute("onclick","void(0)");
						}
						uexWindow.toast("0", "5", data['msg'], 1000);
					}
				}else if(status==-1){
					uexWindow.toast("0","5",'加载超时',1000);
				}
			}
			
			var url=app_path+'index.php?m=iapp&c=user&a=my_coupons&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
			uexXmlHttpMgr.open('1','post',url,"8000");
			uexXmlHttpMgr.send('1');
		}
    }
	
	function post(id){
		var url=app_path+'index.php?m=iappCoupons&c=index&a=forthputting&id='+id+'&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
		uexXmlHttpMgr.open('2','post',url,"8000");
		uexXmlHttpMgr.send('2');
	}
	
	function jump(id){
		localStorage['coupons_id']=id;
		uexWindow.open('coupons_show','0','coupons_show.html','2','', '',0);
	}
	
</script>
</html>